package br.org.credfaz.sis.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import br.org.credfaz.sis.MysqlConnectionFactory;
import br.org.credfaz.sis.modelo.TcePlanoPagamento;

public class TestePlanoPagamentoDAO {
	
private final Connection connection;
	
	public TestePlanoPagamentoDAO(){
		try{
			connection = new MysqlConnectionFactory().getConnection();
		}catch (SQLException e){
			throw new RuntimeException(e);
		}
	}
	
	public void adiciona(TcePlanoPagamento planopagamento){
		String sql = "insert into planopagamento (idmodalidadeproduto, idcliente, numcontratocredito, numparcela," +
				" codsituacaoparcela, qtddiasjurosoperacao, qtddiasjurosaapropriaroper, " +
				"datavencparcela, dataapropriacao, perctaxajurosdiario, valorparcela, valoratualizadoparcela," +
				"valormoraparcela, valormultaparcela, valorapropriadonodia, valorsaldodevedorinicial," +
				"valorjurosaproprperiodo, valororiginalparcela, valoramortizacaoparcela, valorjurosparcela, valorizacaoparcela) " +
				"values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
		
		
		PreparedStatement stmt;
		try{
			stmt = connection.prepareStatement(sql);
			

			stmt.setInt(1, planopagamento.getIdmodalidadeproduto());
			stmt.setLong(2, planopagamento.getIdcliente());
			stmt.setFloat(3, planopagamento.getNumcontratocredito());
			stmt.setInt(4, planopagamento.getNumparcela());
			stmt.setInt(5, planopagamento.getCodsituacaoparcela());
			stmt.setLong(6, planopagamento.getQtddiasjurosoperacao());
			stmt.setLong(7, planopagamento.getQtddiasjurosaapropriaroper());
			stmt.setDate(8, planopagamento.getDatavencparcela());
			stmt.setDate(9, planopagamento.getDataapropriacao());
			stmt.setDouble(10, planopagamento.getPerctaxajurosdiario());
			stmt.setDouble(11, planopagamento.getValorparcela());
			stmt.setDouble(12, planopagamento.getValoratualizadoparcela());
			stmt.setDouble(13, planopagamento.getValormoraparcela());
			stmt.setDouble(14, planopagamento.getValormultaparcela());
			stmt.setDouble(15, planopagamento.getValorapropriadonodia());
			stmt.setDouble(16, planopagamento.getValorsaldodevedorinicial());
			stmt.setDouble(17, planopagamento.getValorjurosaproprperiodo());
			stmt.setDouble(18, planopagamento.getValororiginalparcela());
			stmt.setDouble(19, planopagamento.getValoramortizacaoparcela());
			stmt.setDouble(20, planopagamento.getValorjurosparcela());
			stmt.setDouble(21, planopagamento.getValorizacaoparcela());
			
			stmt.execute();
			
		}catch (SQLException e){
			throw new RuntimeException(e);
		}
	}

}
